//
//  NSDictionary+Extend.m
//  CFFinanceProject
//
//  Created by chunfeng on 2018/4/9.
//  Copyright © 2018年 xiaowen. All rights reserved.
//

#import "NSDictionary+Extend.h"

@implementation NSDictionary (Extend)

+(NSDictionary *)getDictionryWithParametersArray:(NSArray *)parametersArray{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    if (!parametersArray) {
        NSLog(@"参数不存在");
    }else if (!parametersArray.count){
        NSLog(@"参数个数为空为空");
    }else{
        for (NSString * str in parametersArray) {
            if (![str isNullOrEmpty]) {
                dic[str] = str;
            }
        }
    }
    return [dic copy];
}

-(void)addKeyValue:(NSString *)keyValue{
    if (![keyValue isNullOrEmpty]) {
        [self setValue:NSStringFromClass([keyValue class]) forKey:keyValue];
    }else{
        NSLog(@"");
    }
    
}


+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonStr
{
    if (jsonStr == nil) {
        return nil;
    }
    NSData* jsonData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
    if (err) {
        NSLog(@"json serialize failue");
        return nil;
    }
    return dic;
}

- (NSString*)jsonString
{
    NSData* infoJsonData = [NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted error:nil];
    NSString* json = [[NSString alloc] initWithData:infoJsonData encoding:NSUTF8StringEncoding];
    return json;
}


@end
